package com.lh.tams.controller.system;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lh.tams.controller.qo.NoticeQo;
import com.lh.tams.domain.TamsNotice;
import com.lh.tams.domain.TamsPerson;
import com.lh.tams.service.system.NoticeService;
import com.lh.tams.util.Constants;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.ID;
import com.lh.tams.util.Page;
import com.lh.tams.util.Status;
import com.lh.tams.util.diy.Json;

/**
 * 公告管理controller
 * @author liulin
 * @version 2012-05-17
 */
@RequestMapping("/notice")
@Controller
public class NoticeController {
	private NoticeService noticeService;

	public NoticeService getNoticeService() {
		return noticeService;
	}

	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}
	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,NoticeQo noticeQo){
		return noticeService.query(dgm, noticeQo);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Json add(TamsNotice notice,HttpSession session){
		//获取session用户
		TamsPerson person= (TamsPerson) session.getAttribute(Constants.ADMIN_SESSION_KEY);
		
		notice.setIdBgt(ID.next());
		notice.setStatus(Status.STATUS_NORMAL);
		notice.setCreateDate(new Date());
		notice.setIsUp(0);
		notice.setTamsPerson(new TamsPerson(person.getIdBgt()));
		noticeService.add(notice);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/update.adm")
	@ResponseBody
	public Json update(TamsNotice notice,long personId){
		notice.setTamsPerson(new TamsPerson(personId));
		noticeService.update(notice);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Json delete(long[] id){
		noticeService.delete(id);
		return new Json();
	}
}
